package cn.lijiancn01.demo.framework.config.mybatis;

import cn.lijiancn01.demo.framework.model.BaseDO;
import cn.lijiancn01.demo.framework.util.MyConstants;
import com.mybatisflex.core.FlexGlobalConfig;
import com.mybatisflex.core.logicdelete.LogicDeleteProcessor;
import com.mybatisflex.spring.boot.MyBatisFlexCustomizer;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class MyBatisFlexConfiguration implements MyBatisFlexCustomizer {

    @Override
    public void customize(FlexGlobalConfig globalConfig) {
        //设置逻辑删除字段
        globalConfig.setLogicDeleteColumn(MyConstants.LOGIC_DELETE_COLUMN);
        //设置数据库正常时的值
        globalConfig.setNormalValueOfLogicDelete(MyConstants.N);
        //设置数据已被删除时的值
        globalConfig.setDeletedValueOfLogicDelete(MyConstants.Y);

        globalConfig.registerInsertListener(new MyInsertListener(), BaseDO.class);
        globalConfig.registerUpdateListener(new MyUpdateListener(), BaseDO.class);
        globalConfig.registerSetListener(new MySetListener(), BaseDO.class);
    }

    @Bean
    public LogicDeleteProcessor logicDeleteProcessor() {
        //自定义逻辑删除
        return new MyLogicDeleteProcessor();
    }

}
